package fhq.hcmute.qrcode.common;


/**
 * @author: Hien Nguyen Le
 * @Email: nglehien@gmail.com
 */
public class BinaryImage extends OtsuThresholder {

	private final int width;
	private final int height;
	public static final int BLACK = 0;
	public static final int WHITE = 255;

	public BinaryImage(int width, int height, byte[] srcData) {
		super(width, height, srcData);
		this.width = width;
		this.height = height;
	}

	public int getWidth() {
		return width;
	}

	public int getHeight() {
		return height;
	}

	/**
	 * @return True if get black pixel.
	 */
	public boolean getPixel(int i, int j) {
		return matrix[i][j] == BLACK;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		for (int i = 0; i < this.height; i++) {
			for (int j = 0; j < this.width; j++) {
				if (matrix[i][j] == BLACK) {
					builder.append("X");
				} else {
					builder.append(" ");
				}
			}
			builder.append("\n");
		}
		return builder.toString();
	}
}
